<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/3
 * Time: 11:11
 */

namespace app\api\controller;


use app\common\controller\ApiBase;
use think\Request;
use think\Controller;
use app\common\model\Slide as SlideModel;
use app\common\model\User as UserModel;
use think\Db;

class Home extends ApiBase{
    protected  $slide_model;
    protected  $user_model;
    protected function _initialize()
    {
        parent::_initialize();
        $this->slide_model = new SlideModel();
        $this->user_model = new UserModel();
    }

    // 写入检查日志
    public function jss($jss){
        $jsss = ['json_str'=>$jss,'check_time'=>time()];
        $data = Db::name('wxurlscheck')->insert($jsss);
        return json($data);
    }

    public function show(){
        $data = Db::name('wxurlscheck')->order('check_time desc')->limit(10)->select();
        $last_data = array();
        foreach ($data as $dd) {
            $a_array = [
                'id' => $dd['id'],
                'json_str' => $dd['json_str'],
                'nowtime' => date("Y-m-d H:i:s",$dd['check_time'])
            ];
            array_push($last_data,$a_array);
        }
        return json($last_data);
    }

    /*
     * 页面数据
     * 轮播图 - 功能分类
     *
     * */
    public function home(){
        //  轮播图
        //  功能页
        $slide = $this->slide();
        $recommend = $this->recommend();

        $big_array = [
            'imglist'=> $slide,
            'indicatorDots'=> false,
            'autoplay'=>true,
            'interval'=> 5000,
            'duration'=>1000,
            'indicatorDotsOne'=>false,
            'autoplayOne'=>false,
            'currentItem'=>0,
            'indexnavlist'=> [
                ['id'=>'1',
                    'imageurl'=>'https://www.easyicon.net/api/resizeApi.php?id=1177444&size=128',
                    'title'=>'最新资讯',
                    'link'=>''
                ],
                ['id'=>'1',
                    'imageurl'=>'https://www.easyicon.net/api/resizeApi.php?id=1177444&size=128',
                    'title'=>'最新资讯',
                    'link'=>'']
            ],
            'recommendlist'=>$recommend,
            'nearbylist'=>$recommend
        ];
        return $this->thinkJsonCodeMsg($big_array,200,'ok');
    }

    /*
     * 轮播图
     * */
    public function slide(){
        $result = $this->slide_model->field('id,image,link')->select();
//        dump($result);
        return $result;
    }

    /*
     * 功能页
     * */
    public function funcs(){
        $list_array = [

        ];

    }

    /*
     * 用户列表
     * */

    public function recommend(){
        $result = $this->user_model->field('id,headImg,nickname,sex,city,province,birthday')->select();
//        dump($result);
        return $result;
    }

    public function nearbylist(){

    }

    /*
     * 用户信息
     * */
    public function infomation($id){

    }





}
